layui.define(['table', 'jquery', 'element','facade','laytpTab'], function(exports) {
	"use strict";

	var MOD_NAME = 'menu',
		$ = layui.jquery,
		element = layui.element;
    var laytpTab = layui.laytpTab;

	var laytpMenu = function(opt) {
		this.option = opt;
	};

    var page_style_type = sessionStorage.getItem('page_style_type');
    if(!page_style_type){
        page_style_type = 2;
        sessionStorage.setItem('page_style_type',page_style_type);
    }

	if(page_style_type == 1){

        // 供外部调用的，渲染菜单方法
        laytpMenu.prototype.render = function(opt) {
            var option = {
                elem: opt.elem,
                async: opt.async,
                parseData: opt.parseData,
                url: opt.url,
                method: opt.method ? opt.method : "GET",
                defaultOpen: opt.defaultOpen,
                defaultSelect: opt.defaultSelect,
                control: opt.control,
                defaultMenu: opt.defaultMenu,
                accordion: opt.accordion,
                height: opt.height,
                theme: opt.theme,
                data: opt.data ? opt.data : [],
                change: opt.change ? opt.change : function() {},
                done: opt.done ? opt.done : function() {}
            };
            if (option.async) {
                $.ajax({
                    url: server_api_name + option.url,
                    type: option.method,
                    data: {token: facade.getCookie('token'), pid: 0},
                    dataType: 'json',
                    success:function (res) {
                        if(res.code === 2000) {
                            localStorage.setItem('yi_menu', JSON.stringify(res.data));
                            if(res.data.length > 0) {
                                createMenuAndControl(res.data);
                            }
                            element.init();
                        }
                        if($("#sideMenu").attr('menukey') > 0){
                            $("#sideMenu").attr('menukey', 0);
                            $("#sideMenu ul li:first-child").click();
                        }
                    }
                })
            }
            // 处理高度
            $("#"+opt.elem).height(option.height);
            return new laytpMenu(opt);
        };


        // 点击事件
        laytpMenu.prototype.click = function(clickEvent) {
            // 一级菜单点击事件
            $(document).off("click", "#sideMenu li").on("click", "#sideMenu li", function() {
                var menu_id = $(this).attr("menu-id");
                var menu_color = $(this).attr("menu-color");
                var menu_icon = $(this).attr("menu-icon");
                var menu_title = $(this).attr("menu-title");

                // 查询遍历二级菜单
                $.ajax({
                    url: server_api_name + ask_getusermenu,
                    type: 'post',
                    data: {token: facade.getCookie('token'), pid: menu_id},
                    dataType: 'json',
                    success:function (res) {
                        if(res.code === 2000) {
                            localStorage.setItem('er_menu', JSON.stringify(res.data));

                            // 遍历二级菜单
                            if(res.data.length > 0) {
                                var control = '<ul class="layui-nav" lay-filter="control-nav">';
                                $.each(res.data, function(i, item) {
                                    control += '<li class="layui-nav-item">' +
                                        '<a class="site-demo-active" href="javascript:;" menu-url="'+item.href+'" ' +
                                        'menu-id="' + item.id +'" menu-title="'+item.name+'">' + item.name + '</a>';

                                    if(item.children.length > 0){
                                        control += '<dl class="layui-nav-child">';
                                        item.children.forEach(function (v,k) {
                                            control += '<dd><a href="javascript:;" menu-url="'+v.modedir+'" menu-id="'+v.id+'" menu-title="'+v.name+'" menu-pid="'+v.pid+'">' +
                                                '<span style="width: 15px;display: inline-flex;margin-right: 5px"><i class="layui-icon layui-icon-right" style="display: none"></i></span><span>'+v.name+'</span></a></dd>';
                                        });
                                        control += '</dl>';
                                    }

                                    control += '</li>';
                                });
                                control += '</ul>';
                                $("#control").html(control);
                                element.render('control-nav');
                            }


                            if($("#control").attr('menukey') > 0){
                                $("#control").attr('menukey', 0);
                                // $("#control ul li:first-child").find('.site-demo-active').click();
                                $("#control ul li:first-child").find('.site-demo-active').css({'border-bottom':'2px solid #1ca5ff','font-weight': 700});
                            }
                        }
                    }
                });

                // 顶部左侧一级菜单信息
                var top_yi_menu_info = '<a href="javascript:void(0);"><i class="'+menu_icon+'" style="color:'+menu_color+';"></i>' +
                    menu_title+'</a>';
                $('#header-left-title').html(top_yi_menu_info);

                // 设置顶部左侧一级菜单和活动的一级菜单id
                localStorage.setItem('top_yi_menu_info',top_yi_menu_info);
                localStorage.setItem('active_yi_menu',menu_id);

                // 一级菜单点击样式处理
                $(document).find("#sideMenu li").each(function () {
                    let menucolor = $(this).attr("menu-color");
                    $(this).css({'background': '#192a5e '});
                    // $(this).find('a').css({'background': '#28333e','color': '#E5E8F1'});
                    $(this).find('a').css({'color': '#E5E8F1'});
                    $(this).find('i').css({'color': menucolor});
                });
                // $(this).css({'background': menu_color});
                // $(this).find('a').css({'background': menu_color, 'color': '#fff'});
                $(this).css({'background': '#263870'});
                $(this).find('a').css({'color': '#fff'});
                $(this).find('i').css({'color': '#fff'});
            });

            // 三级菜单点击事件
            $(document).on("click", "#control li dd a", function() {
                $('#control li').each(function () {
                    $(this).css('cssText','background: none');
                    $(this).find('a').css({'border-bottom':'none','font-weight': 500})
                });
                $(this).parents('li').css('cssText','background: #28333e');
                $(this).parents('li').find('>a').css({'border-bottom':'2px solid #1ca5ff','font-weight': 700});

                var menuId = $(this).attr('menu-id');
                var menuTitle = $(this).attr('menu-title');
                var menuPath = $(this).attr('menu-url');
                clickEvent($(this), {
                    menuId: menuId,
                    menuTitle: menuTitle,
                    menuPath: menuPath,
                    menuUrl: 'page/'+menuPath,
                });
            });



            // 二级菜单点击事件
            $(document).off("click", "#control .site-demo-active").on("click", "#control .site-demo-active", function() {
                if($(this).parent().find('dl').length == 0){ // 判断没有三级菜单可以点击
                    $('#control li').each(function () {
                        $(this).css('cssText','background: none');
                    });
                    $(this).parent().css('cssText','background: #28333e');

                    var dom = $(this);
                    var data = {
                        menuId: dom.attr("menu-id"),
                        menuTitle: dom.attr("menu-title"),
                        menuPath: dom.attr("menu-title"),
                        menuIcon: dom.attr("menu-icon"),
                        menuColor: dom.attr("menu-color"),
                        menuUrl: dom.attr("menu-url"),
                        openType: dom.attr("open-type")
                    };

                    // 处理二级菜单点击样式问题
                    $("#control li").each(function () {
                        $(this).find('a').css({'border-bottom':'none','font-weight': 500})
                    });
                    $(this).css({'border-bottom':'2px solid #1ca5ff','font-weight': 700});

                    var er_menu = JSON.parse(localStorage.getItem('er_menu'));
                    $.each(er_menu, function(i, note) {
                        // 判断是否存在二级菜单的选项，且按照分类保存，如果有则更新，没有在保存，保存当前打开的二级菜单的id
                        if(data.menuId == note.id){
                            // 保存二级id菜单
                            localStorage.setItem('active_er_menu',note.id);

                            // 切换菜单获取判断,二级菜单是否存在过已经打开过的三级菜单
                            var old_active_er_menu = localStorage.getItem('active_er_menu'+note.id);
                            if(old_active_er_menu){
                                // 存储三级菜单
                                if(note.children && note.children.length > 0){
                                    $.each(note.children, function (i, note2) {
                                        if(old_active_er_menu == note2.id){
                                            // 存储三级菜单
                                            var active_san_menu = {
                                                id: note2['id'],
                                                title: note2['name'],
                                                href: 'page/'+note2['modedir'],
                                                pid: note2['pid'],
                                            };
                                            localStorage.setItem('active_san_menu',JSON.stringify(active_san_menu));
                                        }
                                    })
                                }else{
                                    if(old_active_er_menu == note.id){
                                        // 存储三级菜单
                                        var active_san_menu = {
                                            id: note['id'],
                                            title: note['name'],
                                            href: 'page/'+note['modedir'],
                                            pid: note['pid'],
                                        };
                                        localStorage.setItem('active_san_menu',JSON.stringify(active_san_menu));
                                    }
                                }

                                element.tabChange('content', old_active_er_menu)
                            }else{
                                // 存在三级菜单直接展示三级菜单的第一个菜单, 否则展示二级菜单
                                if(note.children && note.children.length > 0){
                                    // 存储二级菜单下打开的页面 key二级名称，val三级id
                                    localStorage.setItem('active_er_menu'+note.id,note.children[0]['id']);
                                    // 存储三级菜单
                                    var active_san_menu = {
                                        id: note.children[0]['id'],
                                        title: note.children[0]['name'],
                                        href: 'page/'+note.children[0]['modedir'],
                                        pid: note.children[0]['pid'],
                                    };
                                    localStorage.setItem('active_san_menu',JSON.stringify(active_san_menu));
                                    clickEvent(dom, {
                                        menuId: note.children[0]['id'],
                                        menuTitle: note.children[0]['name'],
                                        menuPath: note.children[0]['name'],
                                        menuIcon: note.children[0]['icon'],
                                        menuUrl: 'page/'+note.children[0]['modedir'],
                                        openType: note.children[0]['type'],
                                    });
                                }else{
                                    // 存储二级菜单下打开的页面 key二级名称，val三级id
                                    localStorage.setItem('active_er_menu'+note.id,note.id);
                                    // 存储三级菜单
                                    var active_san_menu = {
                                        id: note['id'],
                                        title: note['name'],
                                        href: 'page/'+note['modedir'],
                                        pid: note['pid'],
                                    };
                                    localStorage.setItem('active_san_menu',JSON.stringify(active_san_menu));

                                    clickEvent(dom, {
                                        menuId: note['id'],
                                        menuTitle: note['name'],
                                        menuPath: note['name'],
                                        menuIcon: note['icon'],
                                        menuUrl: 'page/'+note['modedir'],
                                        openType: note['type'],
                                    });
                                }

                                // 处理历史菜单打开记录 直接打开二级菜单或打开三级菜单
                                var open_menu = sessionStorage.getItem('open_menu');
                                var menuArr = JSON.parse(open_menu);
                                menuArr.push(active_san_menu);
                                sessionStorage.setItem('open_menu', JSON.stringify(menuArr));

                                var str = '';
                                str += '<span class="box-span box_span_bac" key="'+active_san_menu.id+'">';
                                str += '<span class="box-title" onclick="box_jump('+active_san_menu.id+',\''+active_san_menu.href+'\',\''+active_san_menu.title+'\','+active_san_menu.pid+')">'+active_san_menu.title+'</span>';
                                str += '<span class="box-close" onclick="box_close(this, '+active_san_menu.id+',\''+active_san_menu.href+'\','+active_san_menu.pid+')"></span>';
                                str += '</span>';
                                $('#footer_box .box').append(str);
                                $('#footer_box #history_num').text(menuArr.length);
                            }
                        }
                    });
                }
            })
        };


        // 样式选择
        laytpMenu.prototype.skin = function(skin) {
            var menu = $(".laytp-nav-tree[lay-filter='" + this.option.elem + "']").parent();
            menu.removeClass("dark-theme");
            menu.removeClass("light-theme");
            menu.addClass(skin);
        };

        // 选择没有子级的菜单节点
        laytpMenu.prototype.selectItem = function(laytpId) {
            if (this.option.control != false) {
                $("#" + this.option.elem + " a[menu-id='" + laytpId + "']").parents(".layui-side-scroll ").find("ul").css({
                    display: "none"
                });
                $("#" + this.option.elem + " a[menu-id='" + laytpId + "']").parents(".layui-side-scroll ").find(".layui-this").removeClass(
                    "layui-this");
                $("#" + this.option.elem + " a[menu-id='" + laytpId + "']").parents("ul").css({
                    display: "block"
                });
                var controlId = $("#" + this.option.elem + " a[menu-id='" + laytpId + "']").parents("ul").attr("menu-id");
                if (controlId != undefined) {
                    $("#" + this.option.control).find(".layui-this").removeClass("layui-this");
                    $("#" + this.option.control).find("[menu-id='" + controlId + "']").addClass("layui-this");
                }
            }
            if (this.option.accordion === true) {
                $("#" + this.option.elem + " a[menu-id='" + laytpId + "']").parents(".laytp-nav-tree").find(".layui-nav-itemed").removeClass(
                    "layui-nav-itemed");
            }
            $("#" + this.option.elem + " a[menu-id='" + laytpId + "']").parents(".laytp-nav-tree").find(".layui-this").removeClass(
                "layui-this");
            if (!$("#" + this.option.elem).is(".laytp-nav-mini")) {
                $("#" + this.option.elem + " a[menu-id='" + laytpId + "']").parents(".layui-nav-item").addClass("layui-nav-itemed");
                $("#" + this.option.elem + " a[menu-id='" + laytpId + "']").parents("dd").addClass("layui-nav-itemed");
            }
            $("#" + this.option.elem + " a[menu-id='" + laytpId + "']").parent().addClass("layui-this");
        }

        // 手机模式下，右下角按钮点击展开收缩左侧菜单事件
        laytpMenu.prototype.collaspe = function(time) {
            var elem = this.option.elem;
            var config = this.option;
            if ($("#" + this.option.elem).is(".laytp-nav-mini")) {
                $("#layui-side").removeClass("nav49");
                $("#layui-side .title").removeClass('none');
                $("#layui-side .logo").hide();
                $('.layui-header').removeClass('mobile-header');
                $('.layui-body').removeClass('mobile-body');
                $("#sideMenu .layui-side-scroll").css("cssText","width:120px !important");
                $("#sideMenu .layui-side-scroll .layui-nav").css("cssText","width:120px !important");
                $("#sideMenu .layui-side-scroll .layui-nav a").css("cssText","text-overflow: ellipsis");
                $("#" + this.option.elem).removeClass("laytp-nav-mini");
            } else {
                $("#layui-side").addClass("nav49");
                $("#layui-side .title").addClass('none');
                $("#layui-side .logo").show();
                $('.layui-header').addClass('mobile-header');
                $('.layui-body').addClass('mobile-body');
                $("#sideMenu .layui-side-scroll").css("cssText","width:50px !important");
                $("#sideMenu .layui-side-scroll .layui-nav").css("cssText","width:50px !important");
                $("#sideMenu .layui-side-scroll .layui-nav a").css("cssText","text-overflow: unset");
                $("#" + this.option.elem).addClass("laytp-nav-mini");
            }
        };

	}else{
        $(".laytp-admin .layui-side").addClass('navzuo1');
        $(".laytp-admin .layui-side-scroll").addClass('navzuo1');
        $(".laytp-admin .layui-body").css('left','200px');
        $(".laytp-admin .layui-header").css('left','200px');
        $(".laytp-admin .layui-header").css('width','calc(100% - 200px)');


        // 供外部调用的，渲染菜单方法
        laytpMenu.prototype.render = function(opt) {
            var option = {
                elem: opt.elem,
                async: opt.async,
                parseData: opt.parseData,
                url: opt.url,
                method: opt.method ? opt.method : "GET",
                defaultOpen: opt.defaultOpen,
                defaultSelect: opt.defaultSelect,
                control: opt.control,
                defaultMenu: opt.defaultMenu,
                accordion: opt.accordion,
                height: opt.height,
                theme: opt.theme,
                data: opt.data ? opt.data : [],
                change: opt.change ? opt.change : function() {},
                done: opt.done ? opt.done : function() {}
            };
            if (option.async) {
                $.ajax({
                    url: server_api_name + option.url,
                    type: option.method,
                    data: {token: facade.getCookie('token'), pid: 0},
                    dataType: 'json',
                    success:function (res) {
                        if(res.code === 2000) {
                            localStorage.setItem('yi_menu', JSON.stringify(res.data));
                            if(res.data.length > 0) {
                                createMenuAndControl(res.data);
                            }
                            element.init();
                        }
                        if($("#control").attr('menukey') > 0){
                            $("#control").attr('menukey', 0);
                            $("#control ul li:first-child").click();
                        }
                    }
                })
            }
            // 处理高度
            $("#"+opt.elem).height(option.height);
            return new laytpMenu(opt);
        };


        $(document).on("mouseover", "#control li", function() {
            $(this).addClass('top-menu-hover');
        });
        $(document).on("mouseout", "#control li", function() {
            $(this).removeClass('top-menu-hover');
        });



        // 点击事件
        laytpMenu.prototype.click = function(clickEvent) {
            // 一级菜单点击事件
            $(document).off("click", "#control li").on("click", "#control li", function() {
                var menu_id = $(this).attr("menu-id");
                var menu_color = $(this).attr("menu-color");
                var menu_icon = $(this).attr("menu-icon");
                var menu_title = $(this).attr("menu-title");

                // 查询遍历二级菜单
                $.ajax({
                    url: server_api_name + ask_getusermenu,
                    type: 'post',
                    data: {token: facade.getCookie('token'), pid: menu_id},
                    dataType: 'json',
                    success:function (res) {
                        if(res.code === 2000) {
                            localStorage.setItem('er_menu', JSON.stringify(res.data));

                            // 遍历二级菜单
                            if(res.data.length > 0) {
                                var control = '<ul class="layui-nav layui-nav-tree letnavurl" lay-filter="control-nav">';
                                $.each(res.data, function(i, item) {
                                    control += '<li class="layui-nav-item" style="position: relative;">' +
                                        '<a class="site-demo-active sideli_a" href="javascript:;" menu-url="'+item.modedir+'" ' +
                                        'menu-id="' + item.id +'" menu-title="'+item.name+'" title="'+item.name+'">' +
                                        '<img src="/static/admin/images/xxx/'+item.icon+'.png" style="width: 25px;">&nbsp;&nbsp;&nbsp;' + item.name;

                                    if(item.children.length > 0){
                                        control += '<span style="width: 15px;display: inline-flex;float: right;margin-right: 5px"><i class="layui-icon layui-icon-right"></i></span>';
                                    }
                                    control += '</a>';

                                    // control += '<a class="site-demo-active sideli_icon" style="display: none;" href="javascript:;" menu-url="'+item.modedir+'" ' +
                                    //     'menu-id="' + item.id +'" menu-title="'+item.name+'" title="'+item.name+'"><img src="/static/admin/images/xxx/'+item.icon+'.png" style="width: 25px;"></a>';

                                    // 遍历三级菜单
                                    if(item.children.length > 0){
                                        control += '<div class="sideClick" key="0" style="display: none;">';
                                        control += '<ul>';
                                        item.children.forEach(function (v,k) {
                                            control += '<li><a href="javascript:;" menu-url="'+v.modedir+'" menu-id="'+v.id+'" menu-title="'+v.name+'" menu-pid="'+v.pid+'">' +
                                                '<span style="width: 15px;display: inline-flex;margin-right: 5px"><i class="layui-icon layui-icon-radio" style="display: none"></i></span><span>&nbsp;&nbsp;'+v.name+'</span></a></li>';
                                        });
                                        control += '</ul>';
                                        control += '</div>';
                                    }

                                    control += '</li>';
                                });
                                control += '</ul>';
                                $("#sideMenu").html(control);
                                element.render('control-nav');
                            }


                            // if($("#control").attr('menukey') > 0){
                            //     $("#control").attr('menukey', 0);
                            //     // $("#control ul li:first-child").find('.site-demo-active').click();
                            //     $("#control ul li:first-child").find('.site-demo-active').css({'border-bottom':'2px solid #1ca5ff','font-weight': 700});
                            // }
                        }
                    }
                });

                // 顶部左侧一级菜单信息
                var top_yi_menu_info = '<a href="javascript:void(0);"><i class="'+menu_icon+'" style="color:'+menu_color+';"></i>' +
                    menu_title+'</a>';
                $('#header-left-title').html(top_yi_menu_info);

                // 设置顶部左侧一级菜单和活动的一级菜单id
                localStorage.setItem('top_yi_menu_info',top_yi_menu_info);
                localStorage.setItem('active_yi_menu',menu_id);

                // 一级菜单点击样式处理
                $(document).find("#control li").each(function () {
                    let menucolor = $(this).attr("menu-color");
                    $(this).css({'background': '#454f59'});
                    // $(this).find('a').css({'background': '#454f59','color': '#E5E8F1'});
                    $(this).find('i').css({'color': menucolor});
                });
                // $(this).css({'background': menu_color});
                // $(this).find('a').css({'background': menu_color, 'color': '#fff'});
                $(this).find('a').css({'color': '#fff'});
                $(this).css({'background': '#393d49'});
                $(this).find('i').css({'color': '#fff'});
            });

            // 二级菜单触发三级菜单
            $(document).on("click", "#sideMenu>ul>li>a", function() {
                var that = $(this).parent('li');
                var thisShowNum = that.find('.sideClick').attr('key');
                $('.sideClick').attr('key',0).hide();
                $('#sideMenu li').css('cssText','background-color: #none !important;');
                // that.css('cssText','background-color: #192a5e;');
                if(that.find('div').length == 0){
                    that.css('cssText','background-color: #3c508c;');
                    that.find('a').css('cssText','color:#fff;');
                }
                if(thisShowNum > 0){
                    that.find('div').attr('key',0).hide();
                }else{
                    that.find('div').attr('key',1).show();
                    that.find('div').css('cssText','background-color: #122150 !important;');
                    if($("#layui-side").hasClass('nav49')){
                        var top = that.offset().top;
                        var left = $('#layui-side').width();
                        var docHeight = $(document).height();
                        var divHeight = that.find('div').height();
                        if((docHeight - top) < (divHeight + 36)){
                            top = top - divHeight + 44;
                        }
                        that.find('div').css('cssText','position: fixed;background: #122150;color:#fff;top:'+top+'px;left:'+left+'px');
                    }
                }


                that.removeClass('layui-this');
            });

            $(document).on("mouseout", "#sideMenu>ul>li", function() {
                $(this).find('div>ul>li').mouseover(function () {
                    // $(this).css('cssText',"font-weight: bold;");
                    $(this).find('span i').show();
                    // $(this).parent().parent().show()
                });

                $(this).find('div>ul>li').mouseout(function () {
                    $(this).find('span i').hide();
                });
            });


            // 二级菜单点击事件
            $(document).on("click", "#sideMenu>ul>li", function() {
                if($(this).find('div').length == 0){ // 判断没有三级菜单可以点击
                    var dom = $(this).find('a');
                    var data = {
                        menuId: dom.attr("menu-id"),
                        menuTitle: dom.attr("menu-title"),
                        menuPath: dom.attr("menu-title"),
                        menuIcon: dom.attr("menu-icon"),
                        menuColor: dom.attr("menu-color"),
                        menuUrl: 'page/'+dom.attr("menu-url"),
                        openType: dom.attr("open-type")
                    };

                    clickEvent(dom, data);
                }
            });


            // 三级级菜单点击事件
            $(document).off("click", "#sideMenu>ul>li>div>ul>li").on("click", "#sideMenu>ul>li>div>ul>li", function() {
                $("#sideMenu>ul>li>div>ul>li").find('.layui-icon-radio').hide();
                $('#sideMenu li a').css('cssText','color:#C2C2C2');
                $(this).find('.layui-icon-radio').show();
                var dom = $(this).find('a');
                var data = {
                    menuId: dom.attr("menu-id"),
                    menuTitle: dom.attr("menu-title"),
                    menuPath: dom.attr("menu-title"),
                    menuIcon: dom.attr("menu-icon"),
                    menuColor: dom.attr("menu-color"),
                    menuUrl: 'page/'+dom.attr("menu-url"),
                    openType: dom.attr("open-type")
                };

                clickEvent(dom, data);
            })

        };


        // 样式选择
        laytpMenu.prototype.skin = function(skin) {
            var menu = $(".laytp-nav-tree[lay-filter='" + this.option.elem + "']").parent();
            menu.removeClass("dark-theme");
            menu.removeClass("light-theme");
            menu.addClass(skin);
        };

        // 选择没有子级的菜单节点
        laytpMenu.prototype.selectItem = function(laytpId) {
            // if (this.option.control != false) {
            //     $("#" + this.option.elem + " a[menu-id='" + laytpId + "']").parents(".layui-side-scroll ").find("ul").css({
            //         display: "none"
            //     });
            //     $("#" + this.option.elem + " a[menu-id='" + laytpId + "']").parents(".layui-side-scroll ").find(".layui-this").removeClass(
            //         "layui-this");
            //     $("#" + this.option.elem + " a[menu-id='" + laytpId + "']").parents("ul").css({
            //         display: "block"
            //     });
            //     var controlId = $("#" + this.option.elem + " a[menu-id='" + laytpId + "']").parents("ul").attr("menu-id");
            //     if (controlId != undefined) {
            //         $("#" + this.option.control).find(".layui-this").removeClass("layui-this");
            //         $("#" + this.option.control).find("[menu-id='" + controlId + "']").addClass("layui-this");
            //     }
            // }
            // if (this.option.accordion === true) {
            //     $("#" + this.option.elem + " a[menu-id='" + laytpId + "']").parents(".laytp-nav-tree").find(".layui-nav-itemed").removeClass(
            //         "layui-nav-itemed");
            // }
            // $("#" + this.option.elem + " a[menu-id='" + laytpId + "']").parents(".laytp-nav-tree").find(".layui-this").removeClass(
            //     "layui-this");
            // if (!$("#" + this.option.elem).is(".laytp-nav-mini")) {
            //     $("#" + this.option.elem + " a[menu-id='" + laytpId + "']").parents(".layui-nav-item").addClass("layui-nav-itemed");
            //     $("#" + this.option.elem + " a[menu-id='" + laytpId + "']").parents("dd").addClass("layui-nav-itemed");
            // }
            // $("#" + this.option.elem + " a[menu-id='" + laytpId + "']").parent().addClass("layui-this");
        }

        // 手机模式下，右下角按钮点击展开收缩左侧菜单事件
        laytpMenu.prototype.collaspe = function(time) {
            var elem = this.option.elem;
            var config = this.option;
            if ($("#" + this.option.elem).is(".laytp-nav-mini")) {
                // $('.sideli_a').show();
                // $('.sideli_icon').hide();


                $("#sideMenu>ul>li").each(function () {
                    if($(this).find('.sideClick').attr('key') > 0){
                        $(this).find('.sideClick').css('cssText','position: unset;background-color: rgb(69, 79, 89) !important;');
                    }
                });

                $("#layui-side").removeClass("nav49");
                $("#layui-side .title").removeClass('none');
                $("#layui-side .logo").hide();
                $('.layui-header').removeClass('mobile-header');
                $('.layui-body').removeClass('mobile-body');
                $("#sideMenu .layui-side-scroll").css("cssText","width:120px !important");
                $("#sideMenu .layui-side-scroll .layui-nav").css("cssText","width:120px !important");
                $("#sideMenu .layui-side-scroll .layui-nav a").css("cssText","text-overflow: ellipsis");
                $("#" + this.option.elem).removeClass("laytp-nav-mini");

            } else {
                // $('.sideli_a').hide();
                // $('.sideli_icon').show();

                $("#sideMenu>ul>li").each(function () {
                    if($(this).find('.sideClick').attr('key') > 0){
                        var top = $(this).offset().top;
                        var left = 49;
                        var docHeight = $(document).height();
                        var divHeight = $(this).find('div').height();
                        if((docHeight - top) < (divHeight + 36)){
                            top = top - divHeight + 44;
                        }
                        $(this).find('.sideClick').css('cssText','position: fixed;background: #454f59;color:#fff;top:'+top+'px;left:'+left+'px');
                    }
                });



                $("#layui-side").addClass("nav49");
                $("#layui-side .title").addClass('none');
                $("#layui-side .logo").show();
                $('.layui-header').addClass('mobile-header');
                $('.layui-body').addClass('mobile-body');
                $("#sideMenu .layui-side-scroll").css("cssText","width:50px !important");
                $("#sideMenu .layui-side-scroll .layui-nav").css("cssText","width:50px !important");
                $("#sideMenu .layui-side-scroll .layui-nav a").css("cssText","text-overflow: unset");
                $("#" + this.option.elem).addClass("laytp-nav-mini");
            }
        };
    }


    // 渲染一级菜单
    function createMenuAndControl(data) {
	    if(page_style_type == 1){

            // 声 明 头 部
            var menu = '<div class="layui-side-scroll">';
            // 获取打开的一级菜单 以及 顶部显示的一级菜单样式
            var active_yi = 0;
            if(localStorage.getItem('active_yi_menu')){
                active_yi = localStorage.getItem('active_yi_menu');
            }
            if(localStorage.getItem('top_yi_menu_info')){
                var top_yi_menu_info = localStorage.getItem('top_yi_menu_info');
                $('#header-left-title').html(top_yi_menu_info);
            }

            var menuItem = '<ul class="layui-nav layui-nav-tree" style="width: 150px;">';
            $.each(data, function(i, item) {
                // 创 建 菜 单 结 构
                if(active_yi == item.id){
                    menuItem += '<li menu-title="' + item.name + '" menu-id="' + item.id + '" ' +
                        'menu-color="'+item.color+'" menu-icon="'+item.icon+'" class="layui-nav-item">' +
                        '<a href="javascript:void(0);" style="color: #fff;">' +
                        '<i class="'+item.icon+'" style="font-size: 38px; color: #fff;"></i>&nbsp;&nbsp;&nbsp;&nbsp;'+ item.name + '</a></li>';

                    // 查询二级菜单
                    $.ajax({
                        url: server_api_name + ask_getusermenu,
                        type: 'post',
                        data: {token: facade.getCookie('token'), pid: item.id},
                        dataType: 'json',
                        success:function (res) {
                            if(res.code === 2000) {
                                localStorage.setItem('er_menu', JSON.stringify(res.data));
                                var active_er_menu = localStorage.getItem('active_er_menu');
                                // 遍历二级菜单
                                if(res.data.length > 0) {
                                    var control = '<ul class="layui-nav">';
                                    $.each(res.data, function(i, item) {
                                        if(active_er_menu == item.id){
                                            control += '<li class="layui-nav-item"><a class="site-demo-active" href="javascript:;" menu-url="'+item.href+'" ' +
                                                'menu-id="' + item.id +'" menu-title="'+item.name+'" style="border-bottom: 2px solid rgb(28, 165, 255); font-weight: 700;">' + item.name + '</a></li>';
                                        }else{
                                            control += '<li class="layui-nav-item"><a class="site-demo-active" href="javascript:;" menu-url="'+item.href+'" ' +
                                                'menu-id="' + item.id +'" menu-title="'+item.name+'">' + item.name + '</a></li>';
                                        }
                                    });
                                    control += 	'</dl></li></ul>';
                                    $("#control").html(control);
                                }
                                // 打开三级菜单
                                if(localStorage.getItem('active_san_menu')){
                                    var active_san = JSON.parse(localStorage.getItem('active_san_menu'));
                                    laytpTab.render({
                                        elem: 'content',
                                        roll: true,
                                        tool: true,
                                        width: '100%',
                                        height: '100%',
                                        index: 2,
                                        id: active_san.id,
                                        url: active_san.href,
                                        title: active_san.title,
                                        close: true,
                                        news: 1, // 新增
                                    });
                                    localStorage.setItem('active_er_menu',active_er_menu);
                                    localStorage.setItem('active_er_menu'+active_er_menu,active_san.id);
                                }
                            }
                        }
                    });

                }else{
                    menuItem += '<li menu-title="' + item.name + '" menu-id="' + item.id + '" ' +
                        'menu-color="'+item.color+'" menu-icon="'+item.icon+'" class="layui-nav-item">' +
                        '<a href="javascript:void(0);" style="letter-spacing: 1px;">' +
                        '<img src="/static/admin/images/menu/'+item.icon+'.png" style="height: 20px;width: 20px">' +
                        // '<i class="'+item.icon+'" style="font-size: 18px; color:'+item.color+';"></i>' +
                        '&nbsp;&nbsp;&nbsp;&nbsp;' + item.name + '</a></li>';
                }
            });
            menu += menuItem;
            menu += '</ul>';
            $("#sideMenu").html(menu);


        }else{

            // 声 明 头 部
            // var menu = '<div class="layui-side-scroll">';
            // 获取打开的一级菜单 以及 顶部显示的一级菜单样式
            var active_yi = 0;
            if(localStorage.getItem('active_yi_menu')){
                active_yi = localStorage.getItem('active_yi_menu');
            }
            if(localStorage.getItem('top_yi_menu_info')){
                var top_yi_menu_info = localStorage.getItem('top_yi_menu_info');
                $('#header-left-title').html(top_yi_menu_info);
            }

            var menu = '';
            var menuItem = '<ul class="layui-nav">';
            $.each(data, function(i, item) {
                // 创 建 菜 单 结 构
                if(active_yi == item.id){
                    menuItem += '<li menu-title="' + item.name + '" menu-id="' + item.id + '" ' +
                        'menu-color="'+item.color+'" menu-icon="'+item.icon+'" class="layui-nav-item">' +
                        '<a href="javascript:void(0);" style="color: #fff;">' +
                        '<i class="'+item.icon+'" style="font-size: 38px; color: #fff;"></i>&nbsp;'+ item.name + '</a></li>';

                    // 查询二级菜单
                    $.ajax({
                        url: server_api_name + ask_getusermenu,
                        type: 'post',
                        data: {token: facade.getCookie('token'), pid: item.id},
                        dataType: 'json',
                        success:function (res) {
                            if(res.code === 2000) {
                                localStorage.setItem('er_menu', JSON.stringify(res.data));
                                var active_er_menu = localStorage.getItem('active_er_menu');
                                // 遍历二级菜单
                                if(res.data.length > 0) {
                                    var control = '<ul class="layui-nav layui-nav-tree" style="width: 120px;">';
                                    $.each(res.data, function(i, item) {
                                        if(active_er_menu == item.id){
                                            control += '<li class="layui-nav-item"><a class="site-demo-active" href="javascript:;" menu-url="'+item.modedir+'" ' +
                                                'menu-id="' + item.id +'" menu-title="'+item.name+'" style="border-bottom: 2px solid rgb(28, 165, 255); ">' + item.name + '</a></li>';
                                        }else{
                                            control += '<li class="layui-nav-item"><a class="site-demo-active" href="javascript:;" menu-url="'+item.modedir+'" ' +
                                                'menu-id="' + item.id +'" menu-title="'+item.name+'">' + item.name + '</a></li>';
                                        }
                                    });
                                    control += 	'</dl></li></ul>';
                                    $("#sideMenu").html(control);
                                }
                                // 打开三级菜单
                                if(localStorage.getItem('active_san_menu')){
                                    var active_san = JSON.parse(localStorage.getItem('active_san_menu'));
                                    laytpTab.render({
                                        elem: 'content',
                                        roll: true,
                                        tool: true,
                                        width: '100%',
                                        height: '100%',
                                        index: 2,
                                        id: active_san.id,
                                        url: active_san.href,
                                        title: active_san.title,
                                        close: true,
                                        news: 1, // 新增
                                    });
                                    localStorage.setItem('active_er_menu',active_er_menu);
                                    localStorage.setItem('active_er_menu'+active_er_menu,active_san.id);
                                }
                            }
                        }
                    });

                }else{
                    menuItem += '<li menu-title="' + item.name + '" menu-id="' + item.id + '" ' +
                        'menu-color="'+item.color+'" menu-icon="'+item.icon+'" class="layui-nav-item">' +
                        '<a href="javascript:void(0);" style="letter-spacing: 1px;">' +
                        '<img src="/static/admin/images/menu/'+item.icon+'.png" style="height: 20px;width: 20px">' +
                        // '<i class="'+item.icon+'" style="font-size: 18px; color:'+item.color+';"></i>' +
                        '&nbsp;' + item.name + '</a></li>';
                }
            });
            menu += menuItem;
            menu += '</ul>';

            $("#control").html(menu);
        }

    }


    exports(MOD_NAME, new laytpMenu());
});
